package com.ks.utils;

import java.io.File;

import org.apache.log4j.Logger;

public class DeleteFileHandle {

	// 验证字符串是否为正确路径名的正则表达式win版
	private static String matches = "[A-Za-z]:\\\\[^:?\"><*]*";
	// 通过 sPath.matches(matches) 方法的返回值判断是否正确
	// sPath 为路径字符串

	public static final Logger logger = Logger.getLogger(DeleteFileHandle.class);

	
	private static String packPath(String path){
		boolean flag = path.matches(matches);
		System.out.println(flag);
		String basePath = "D:\\MyXFiles\\EclipseWeb\\tt\\target\\tiantuo\\";
		
		return basePath + path;
	}
	
	public static boolean delectFile(String path) {
		boolean flag = false;
		String status = "fail";
		logger.info(path);
		File file = new File(path);
		if (file.exists()) {
			flag = file.delete();
			if (flag) {
				status = "success";
			}
		}
		logger.info(status);
		return flag;
	}

	
	public static void main(String[] args) {
		String basePath = "D:\\MyXFiles\\EclipseWeb\\tt\\target\\tiantuo\\";
		String path = basePath + "upload\\image\\1480253594381.png";
//		boolean rs = DeleteFileHandle.delectFile(path);
//		System.out.println(rs);

		packPath(path);
	}

}
